import http from '@/axios'
import {handleError} from "vue";
import {handleSuccess} from "@/api/index.js";

export const logAPI = {
    // 分页获取日志列表
    getLogList: (params) => http.get('/api/log/list', {params})
        .then(res => handleSuccess(res, '分页获取日志列表成功'))
        .catch(error => handleError(error, '分页获取日志列表失败')),

    // 日志详情
    getLogDetail: (id) => http.get(`/api/log/detail`, {params: {id}})
        .then(res => handleSuccess(res, '获取日志详情成功'))
        .catch(error => handleError(error, '获取日志详情失败')),

// 导出日志
    exportLog: (params) => http.get('/api/log/export', {
        params,
        responseType: 'blob'
    })
        .then(res => {
            // 导出成功处理
            return res;
        })
        .catch(error => {
            // 更健壮的错误处理
            const errorMessage = error.response?.data?.message ||
                error.message ||
                '导出日志失败';
            console.error('Export Error:', error);
            return Promise.reject(new Error(errorMessage));
        })
}